﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public partial class Campus
    {
        public bool IsValid 
        {
            get
            {
                return (GetRuleViolations().Count() == 0);
            }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {

            if (String.IsNullOrEmpty(CampusName))
                yield return new RuleViolation("Campus name is required", "CampusName");

            if (String.IsNullOrEmpty(City))
                yield return new RuleViolation("City is required", "City");

            if (String.IsNullOrEmpty(Country))
                yield return new RuleViolation("Country is required", "Country");

            yield break;
        }

        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if(!IsValid)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }
}